package hotel.action;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import hotel.service.IHotelReviewService;
import common.action.BaseAction;
import common.pojo.Review;
import common.utils.Page;
import common.utils.PageUtil;
import common.utils.PaginationUtil;
import static common.utils.Constants.LIMIT;

@Scope("prototype")
@Controller("hotelReviewAction")
public class HotelReviewAction extends BaseAction {

	/**
	 * 查询点评列表
	 */
	public String getHotelReviewListByPage() throws Exception {
		String currentTmp = request.getParameter("current");
		String where = " where status=1 ";
		Page page = getPage(currentTmp, where);
		resultlist = reviewService.find(where, page.getBeginIndex(), LIMIT,
				"id desc");
		pagination = PaginationUtil.getPaginationStyleTwo(page,
				"getHotelReviewListByPage.action");
		return "getReviewList";
	}

	/**
	 * 查询待审核的点评列表
	 */
	public String getCheckListByPage() throws Exception {
		String currentTmp = request.getParameter("current");
		String where = " where status =0 ";
		Page page = getPage(currentTmp, where);
		resultlist = reviewService.find(where, page.getBeginIndex(), LIMIT,
				"id desc");
		pagination = PaginationUtil.getPaginationStyleTwo(page,
				"getCheckListByPage.action");
		return "getCheckList";
	}

	
	public Page getPage(String currentTmp, String where) {
		int total = reviewService.getCount(where);
		int current = PageUtil.getCurrent(currentTmp);
		Page page = PageUtil.createPage(LIMIT, total, current);		
		return page;
	}

	/**
	 * 审核点评
	 */
	public String ispass() {
		String ids = request.getParameter("ids");
		reviewService.verify(ids);
		return SUCCESS;
	}

	/**
	 * 根据id查找信息
	 * 
	 * @return
	 */
	public String findById() {
		int id = Integer.valueOf(request.getParameter("id"));
		review = reviewService.find(id);
		return "detail";
	}

	/**
	 * 删除点评
	 */
	public String delete() {
		String ids = request.getParameter("ids");
		reviewService.delete(ids);
		return SUCCESS;
	}

	private static final long serialVersionUID = 1L;
	@Resource
	private IHotelReviewService reviewService;
	private List<Review> resultlist;
	private String pagination;
	private Review review;


	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}

	public Review getReview() {
		return review;
	}

	public void setReview(Review review) {
		this.review = review;
	}

	public List<Review> getResultlist() {
		return resultlist;
	}

}
